package com.example.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dao.StuDao;
import com.example.domain.Stu;
import com.example.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StuServiceImpl2 implements StuService {

    @Autowired
    private StuDao stuDao;

    @Override
    public Boolean save(Stu stu) {
        return stuDao.insert(stu) > 0;
    }

    @Override
    public Boolean update(Stu stu) {
        return stuDao.updateById(stu) > 0;
    }

    @Override
    public Boolean delete(Integer id) {
        return stuDao.deleteById(id) > 0;
    }

    @Override
    public Stu getById(Integer id) {
        return stuDao.selectById(id);
    }

    @Override
    public List<Stu> getAll() {
        return stuDao.selectList(null);
    }

    @Override
    public IPage<Stu> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        stuDao.selectPage(page,null);
        return page;
    }
}
